package reflectx

import (
	"gitee.com/zhongguo168a/gocodes/datax/schemax"
)

type FuncTypeRef struct {
}

func (f *FuncTypeRef) RefNew() IRefObject {
	return &schemax.FuncType{}
}

func (f *FuncTypeRef) RefType() string {
	return "func"
}

func (f *FuncTypeRef) RefHas(field string) bool {
	switch field {
	case "Args":
		return true
	case "Results":
		return true
	}
	return false
}
func (f *FuncTypeRef) RefGet(target IRefObject, FuncType string) (val interface{}, isNil bool) {
	obj := target.(*schemax.FuncType)
	switch FuncType {
	case "Args":
		return obj.Args, false
	case "Results":
		return obj.Results, false
	}
	return nil, true
}

func (f *FuncTypeRef) RefSet(target IRefObject, FuncType string, val interface{}) {
	obj := target.(*schemax.FuncType)
	switch FuncType {
	case "Args":
		obj.Args = val.([]*schemax.Field)
	case "Results":
		obj.Results = val.([]*schemax.Field)
	}
	return
}

func (desc *FuncTypeRef) RefSliceLength(target IRefObject, key string) int {
	obj := target.(*schemax.FuncType)
	switch key {
	case "Args":
		return len(obj.Args)
	case "Results":
		return len(obj.Results)
	}
	return 0
}
func (desc *FuncTypeRef) RefSliceGet(target IRefObject, key string, index int) (interface{}, bool) {
	obj := target.(*schemax.FuncType)
	switch key {
	case "Args":
		val := obj.Args[index]
		return val, val == nil
	case "Results":
		val := obj.Results[index]
		return val, val == nil
	}
	return nil, true
}
func (desc *FuncTypeRef) RefSliceSet(target IRefObject, key string, index int, val interface{}) {
	obj := target.(*schemax.FuncType)
	switch key {
	case "Args":
		obj.Args[index] = val.(*schemax.Field)
	case "Results":
		obj.Results[index] = val.(*schemax.Field)
	}
	return
}

func (desc *FuncTypeRef) RefSliceNew(field string, len int, cap int) interface{} {
	switch field {
	case "Args":
		return make([]*schemax.Field, len, cap)
	case "Results":
		return make([]*schemax.Field, len, cap)
	}
	return nil
}
